package kr.co.bettersoft.waitnumbercustomer.adapter;

import java.util.List;

import kr.co.bettersoft.waitnumbercustomer.activity.R;
import kr.co.bettersoft.waitnumbercustomer.common.CommonConstant;
import kr.co.bettersoft.waitnumbercustomer.domain.BusinessKind;

import android.content.Context;
import android.graphics.Typeface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class BusinessKindBtnAdapter extends BaseAdapter {
	private Context context;
	private final List<BusinessKind> entries;
 
	// 폰트
	private Typeface typefaceNanumGothic= null; 
	private Typeface typefaceNanumGothicBold = null;
	
	public BusinessKindBtnAdapter(Context context, List<BusinessKind> entriesFn) {		
		this.context = context;
		this.entries = entriesFn;
		
		// 폰트 지정.
	    typefaceNanumGothic = Typeface.createFromAsset(context.getAssets(), CommonConstant.NanumGothic);  
	    typefaceNanumGothicBold = Typeface.createFromAsset(context.getAssets(), CommonConstant.NanumGothicBold);
	}
 
	public View getView(int position, View convertView, ViewGroup parent) {
 
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
		View gridView;
 
		if (convertView == null) {
 
			gridView = new View(context);
 
			// get layout from mobile.xml
			gridView = inflater.inflate(R.layout.search_store_option_businesskind_btn_adapter, null);
 
			// ** 이 소스를 여기에 두면 한 화면의 이미지가 반복 된다. 아래쪽 return 위로 옮겨주면 이미지 반복 현상이 없다. 
//			// set value into textview
//			TextView textView = (TextView) gridView
//					.findViewById(R.id.label);
//			textView.setText(((CheckMileageMerchants)entries.get(position)).getCompanyName());
//			// set image based on selected text
//			ImageView imageView = (ImageView) gridView
//					.findViewById(R.id.icon);
////			String mobile = entries[position];
//			imageView.setImageBitmap(((CheckMileageMerchants)entries.get(position)).getMerchantImage());
		} else {
			gridView = (View) convertView;
		}
 
		// ** 이미지 반복 현상을 없애기 위해 위쪽의 소스를 여기로 옮겨준다. --> 문제 해결 됨.
		// set value into textview
		TextView textView = (TextView) gridView
				.findViewById(R.id.label);
		textView.setText(((BusinessKind)entries.get(position)).getCONTENT());
		
		View parent_layout = gridView
		.findViewById(R.id.parent_layout);
		
		// 색상을 주면 기본 값이 되서 안될 듯. - xml 파일에서 처리함. 기본선택값은 없는데..
//		Log.d("BusinessKindBtnAdapter","BusinessKindBtnAdapter set bg color");
//		if(position==0){
//			parent_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.sub9_9_1_3));
//		}else{
//			parent_layout.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.sub9_9_2_3));
//		}
		
		
//		// set image based on selected text
//		ImageView imageView = (ImageView) gridView
//				.findViewById(R.id.icon);
////		String mobile = entries[position];
//		imageView.setImageBitmap(((BusinessKind)entries.get(position)).getMerchantImage());
		
		// 폰트 적용
		textView.setTypeface(typefaceNanumGothic);		
		
		return gridView;
	}
 
	@Override
	public int getCount() {
		return entries.size();
	}
 
	@Override
	public Object getItem(int position) {
		return null;
	}
 
	@Override
	public long getItemId(int position) {
		return 0;
	}
 
}